package main;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class CoincidirDatosJugadores {
	private static Connection conexion;
	private static ArrayList<Integer> listaJugadores;
	/**
	 * @param args
	 * @throws ClassNotFoundException 
	 * @throws SQLException 
	 */
	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		// TODO Auto-generated method stub
		ResultSet rs; Statement st;
		ResultSet rs1; Statement st1;
		ResultSet rs2; Statement st2;
		ResultSet rs3; Statement st3;
		Class.forName("com.mysql.jdbc.Driver");
		conexion = DriverManager.getConnection("jdbc:mysql://localhost/proyecto", "root", "gracias");
		st = conexion.createStatement(); st1 = conexion.createStatement(); st2 = conexion.createStatement();
		st3 = conexion.createStatement();
		listaJugadores = new ArrayList<Integer>();
		int id; int numP = 0; int numF = 0;
		rs = st.executeQuery("SELECT idPlayer FROM players");
		while(rs.next()) {
			id = rs.getInt("idPlayer");
			rs1 = st1.executeQuery("SELECT MAX(numberMatch) FROM gameplaymatchuser WHERE idPlayer = '"+id+"'");
			while(rs1.next()) {
				numP = rs1.getInt(1);
			}
			rs1 = st1.executeQuery("SELECT numberMatches FROM gamesummaryglobalplayer WHERE idPlayer = '"+id+"'");
			while(rs1.next()) {
				numF = rs1.getInt(1);
			}
			if(numP != numF) {
				System.out.println("Actualizando jugador: "+id);
				st1.executeUpdate("UPDATE gamesummaryglobalplayer SET numberMatches = '"+numP+"' WHERE idPlayer = '"+id+"'");
			}
			rs1.close();
		}
		rs.close();

	}

}
